#include <iostream>
#include <thread>
#include <deque>
#include <ctime>
using namespace std;
#define THREAD 50
 
void t1()  //普通的函数，用来执行线程
{
		cout << "t1111\t";
		this_thread::sleep_for(std::chrono::seconds(1));
}
void t2()
{
		cout << "t22222\t";
		this_thread::sleep_for(std::chrono::seconds(1));
}
void t3()
{
		cout << "t33333\t";
		this_thread::sleep_for(std::chrono::seconds(1));
}
void t4()
{
		cout << "t44444\t";
		this_thread::sleep_for(std::chrono::seconds(1));
}
void t5()
{
		cout << "t55555\t";
		this_thread::sleep_for(std::chrono::seconds(1));
}
void t(int i)
{
		cout << i << "\t";
		this_thread::sleep_for(std::chrono::milliseconds(200));
		deque<int> * pd = new deque<int>[50000];
		delete [] pd;
}
int main()
{
	// thread th1(t1);  //实例化一个线程对象th1，使用函数t1构造，然后该线程就开始执行了（t1()）
	// thread th2(t2);
	clock_t start,end;

	start = clock();
	thread th[THREAD];

	for (int i = 0; i < THREAD; ++i)
	{
		for (int i = 0; i < THREAD; ++i)
		{
			th[i] = thread(t, i);
		}
		cout<<endl<<"==================="<<endl;
		for (int i = 0; i < THREAD; ++i)
		{
			th[i].join();
		}
	}

	// th1.join();
	// th2.join();

	//or use detach
	//th1.detach();
	//th2.detach();
	end = clock();

	cout << "the run time is :"<<(double)(end - start) / CLOCKS_PER_SEC<<"s\n\n";
 
	return 0;
}